/**
 * 
 */
package multithreading;

import optimization.naturalOptimization.fitness.SimpleFitnessFunction;
import optimization.naturalOptimization.population.individual.Individual;

/**
 * This class provides a thread for parallel Fitness calculation.
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public class FitnessCalculator extends Thread {

	@SuppressWarnings("rawtypes")
	private Individual individual;
	@SuppressWarnings("rawtypes")
	private SimpleFitnessFunction fitness;

	/**
	 * Creates a new thread to calculate the fitness of the {@link Individual}.
	 * 
	 * @param individual
	 *            the individual to calculate the position of
	 * @param fitness
	 *            fitness function to evaluate position
	 */
	@SuppressWarnings("rawtypes")
	public FitnessCalculator(Individual individual,
			SimpleFitnessFunction fitness) {
		this.individual = individual;
		this.fitness = fitness;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Thread#run()
	 */
	@SuppressWarnings("unchecked")
	public void run() {
		double fit = fitness.getFitness(individual.getPosition());
		individual.setPositionFitness(fit);
	}
}
